<template>
    <div>
        <!-- 头部 -->
        <div>
            <el-button type="primary" @click="showDialog1('add')">添加总装配置表</el-button>
                <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
            <el-form :inline="true" :model="search">
                    <el-form-item label="总装名称" >
                        <el-input v-model="search.name" style="width: 100px;"></el-input>
                    </el-form-item>
                    <el-form-item label="总装编码">
                        <el-input v-model="search.code" style="width: 100px;"></el-input>
                    </el-form-item>
                    <el-form-item label="是否启用">
                        <el-select v-model="search.isEnable" placeholder="请选择">
                             <el-option label="【空】" value=""></el-option>
                            <el-option label="启用" value="1"></el-option>
                            <el-option label="未启用" value="0"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="机型">
                        <el-select v-model="search.type" placeholder="请选择">
                            <el-option label="【空】" value="" ></el-option>
                            <el-option :label="item.type" :value="item.id" v-for="item in allType" :key="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-button type="primary" @click="searchData" icon="el-icon-search">查询</el-button>
                </el-form>
            <el-button slot="reference" type="primary">查询</el-button>
        </el-popover>
        </div>
        <el-table :data="tableData" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="name" label="工序名称" sortable min-width="160"></el-table-column>
            <el-table-column prop="code" label="工序编码" sortable width="120"></el-table-column>
            <el-table-column prop="typeName" label="机型" sortable   min-width="130"></el-table-column>
            <el-table-column prop="rank" label="生产顺序" sortable  width="120"></el-table-column>
            <el-table-column prop="useTime" label="生产时间定额(分钟)" sortable  min-width="130"></el-table-column>
            <el-table-column prop="isEnable" label="启用" width="60">
                <template  slot-scope="scope">
                    <span :class="scope.row.isEnable===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
             <el-table-column prop="performerName" label="执行人" sortable width="100"></el-table-column>
            <el-table-column prop="creatorName" label="创建人" sortable min-width="100"></el-table-column>
            <el-table-column prop="createTime" label="创建时间" sortable min-width="160"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                <template slot-scope="scope">
                    <el-button @click="showDialog1('update',scope.row)" type="text" size="small">编辑</el-button>
                    <el-button @click="showDialog2(scope.row)" type="text" size="small">配置</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>

        <!-- 弹框1 -->
        <el-dialog :title="dialog1.title" width="800px" center :visible.sync="dialog1.isShow" :close-on-click-modal="false" v-dialogDrag>
            <div :style="tableDialogHeightTabPane">
                <el-form class="demo-form-inline" v-model="dialogForm1" label-position="right" label-width="140px" :inline="true">
                    <el-form-item label="总装名称"><el-input v-model="dialogForm1.name" ></el-input></el-form-item>
                    <el-form-item label="总装编码"><el-input v-model="dialogForm1.code" ></el-input></el-form-item>
                    <el-form-item label="总装机型">
                        <el-autocomplete class="inline-input" v-model="dialogForm1.typeName" :fetch-suggestions="querySearch" placeholder="请输入总装机型" @select="handleSelect"></el-autocomplete>
                    </el-form-item>
                    <el-form-item label="工序排序"><el-input v-model="dialogForm1.rank" ></el-input></el-form-item>
                    <el-form-item label="工序耗时">
                        <el-input placeholder="请输入工序耗时" v-model="dialogForm1.useTime" class="inputSuffix">
                            <template slot="append">分钟</template>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="部件数量"><el-input v-model="dialogForm1.nums" ></el-input></el-form-item>
                    <el-form-item label="启用" ><el-switch v-model="dialogForm1.isEnable"  class="inputSuffix"></el-switch></el-form-item>
                    <el-form-item label="工序执行人">
                        <el-select v-model="dialogForm1.performer" placeholder="请选择工序执行人" class="inputSuffix">
                            <el-option v-for="item in charger" :key="item.id" :label="item.name" :value="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="创建人"><el-input v-model="dialogForm1.creatorName" disabled></el-input></el-form-item>
                    <el-form-item label="创建时间"><el-input v-model="dialogForm1.createTime" disabled></el-input></el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer" style="text-align: center;">
                <el-button @click="submitClick" type="primary">确 定</el-button>
            </div>
        </el-dialog>
         <!-- 弹框2-->
        <el-dialog :title="dialog2.title"  center :visible.sync="dialog2.isShow" :close-on-click-modal="false" v-dialogDrag>
            <div :style="tableDialogHeightTabPane">
                 <el-tabs v-model="activeName" @tab-click="handleClick">
                    <el-tab-pane label="输入物料" name="first">
                        <h3 class="dialog-plate-title"><span>物料</span> <el-button class="addBtn" type="primary" @click="showDialog3('物料')">新增</el-button> </h3>
                        <el-table :data="materielList" :highlight-current-row="true" stripe border class="table-index" style="width: 100%;" :header-cell-style="getRowClass" :height="300">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="name.name" label="物料名称" sortable min-width="160"></el-table-column>
                        <el-table-column prop="name.type" label="规格型号" sortable min-width="160"></el-table-column>
                        <el-table-column prop="num" label="数量" sortable  min-width="120"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                            <template slot-scope="scope">
                                <el-button @click="deleteMateriel(scope.row)" type="text" size="small">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                      <h3 class="dialog-plate-title"><span>部件</span> <el-button class="addBtn" type="primary" @click="showDialog3('部件')">新增</el-button></h3>
                        <el-table :data="partsList" :highlight-current-row="true" stripe border class="table-index" style="width: 100%;" :header-cell-style="getRowClass" :height="300">
                        <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
                        <el-table-column prop="name" label="部件名称" sortable min-width="160"></el-table-column>
                        <el-table-column prop="num" label="数量" sortable  min-width="120"></el-table-column>
                        <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                            <template slot-scope="scope">
                                <el-button @click="deleteParts(scope.row)" type="text" size="small">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="技术标准" name="second">
                         <el-button type="primary" @click="showDialog3()">配置技术标准</el-button>
                         <el-table  :data="seclectTechnicalStandard" tooltip-effect="dark"  style="width: 100%" >
                            <el-table-column prop="fileName" label="文件名称"> </el-table-column>
                             <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                                <template slot-scope="scope">
                                    <el-button @click="showDialog4(scope.row)" type="text" size="small">查看</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="对应图纸" name="third">
                         <el-button type="primary" @click="showDialog3()">配置图纸</el-button>
                         <el-table  :data="selectDrawingList" tooltip-effect="dark"  style="width: 100%" >
                            <el-table-column prop="cidName" label="图纸名称"> </el-table-column>
                             <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                                <template slot-scope="scope">
                                    <el-button @click="deleteDrawing(scope.row)" type="text" size="small">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                    <el-tab-pane label="对应SOP" name="fourth">
                        <el-button type="primary" @click="showDialog3()">配置SOP</el-button>
                         <el-table  :data="selectSOPList" tooltip-effect="dark"  style="width: 100%" >
                            <el-table-column prop="fileName" label="SOP名称"> </el-table-column>
                            <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                                <template slot-scope="scope">
                                    <el-button @click="showDialog4(scope.row)" type="text" size="small">查看</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                    </el-tab-pane>
                      <el-tab-pane label="装配过程检验项目配置" name="fifth">
                        <check-table :list="process.list" @addUpdateCheck='addUpdateCheck'></check-table>
                    </el-tab-pane>
                     <el-tab-pane label="输出结果检验项配置" name="sixth">
                         <check-table :list="outOptConfig.list" @addUpdateCheck='addUpdateCheck'></check-table>
                    </el-tab-pane>
                </el-tabs>
            </div>
        </el-dialog>
        <el-dialog :title="dialog3.title" center :visible.sync="dialog3.isShow" :close-on-click-modal="false" v-dialogDrag>
        <!-- 新增总装物料配置 -->
            <div :style="tableDialogHeightTabPane" v-show="activeName=='first'">
                <div v-if="dialog3.title=='新增物料'">
                    <el-form class="demo-form-inline" :model="materielForm" :rules="materielRules" ref="materiel"  label-position="right" label-width="140px">
                        <el-form-item label="物料名称" prop="name">
                            <el-autocomplete v-model="materielForm.name" :fetch-suggestions="querySearchAsync1" placeholder="请输入内容"  @select="handleSelect1" class="width300">
                                <i slot="suffix" v-text="materielForm.type"></i>
                                <template slot-scope="{ item }">
                                    <div class="name" :title="item.value">{{ item.value}}</div>
                                    <div class="dec" :title="item.type">{{ item.type}}</div>
                                </template>
                            </el-autocomplete>
                        </el-form-item>
                        <el-form-item label="物料数量" prop="num"><el-input v-model="materielForm.num" class="width300"></el-input></el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer" style="text-align: center;">
                        <el-button @click="submitMaterielForm" type="primary">确 定</el-button>
                    </div>
                </div>
                 <div v-if="dialog3.title=='新增部件'">
                    <el-form class="demo-form-inline" :model="sparePartsForm" :rules="sparePartsRules" ref="spareParts"  label-position="right" label-width="140px" :inline="true">
                        <el-form-item label="部件名称" prop="name">
                            <el-autocomplete v-model="sparePartsForm.name" :fetch-suggestions="querySearchAsync2" placeholder="请输入内容"  @select="handleSelect2"></el-autocomplete>
                        </el-form-item>
                        <el-form-item label="部件数量" prop="num"><el-input v-model="sparePartsForm.num" ></el-input></el-form-item>
                    </el-form>
                    <div slot="footer" class="dialog-footer" style="text-align: center;">
                        <el-button @click="submitPartsForm" type="primary">确 定</el-button>
                    </div>
                </div>
            </div>
            <!-- 配置技术标准 -->
            <div :style="tableDialogHeightTabPane" v-show="activeName=='second'">
                  <el-table ref="multipleTable" :data="allTechnicalStandard" tooltip-effect="dark"  style="width: 100%" @selection-change="handleSelectionChange">
                    <el-table-column type="selection" width="55"> </el-table-column>
                    <el-table-column prop="fileName" label="文件名称"> </el-table-column>
                </el-table>
                <div slot="footer" class="dialog-footer" style="text-align: center;">
                    <el-button @click="addFile" type="primary">确 定</el-button>
                </div>
            </div>

            <!-- 配置图纸 -->
            <div :style="tableDialogHeightTabPane" v-show="activeName=='third'">
                 <el-tree
                 ref="drawTress"
                :props="props1"
                node-key="id"
                :load="loadNode"
                lazy
                show-checkbox
                :data="allDrawing">
                </el-tree>
                <div slot="footer" class="dialog-footer" style="text-align: center;">
                    <el-button @click="addDrawing" type="primary">确 定</el-button>
                </div>
            </div>
            <!-- 配置SOP -->
            <div :style="tableDialogHeightTabPane" v-show="activeName=='fourth'">
                  <el-table ref="sop" :data="allSOP" tooltip-effect="dark"  style="width: 100%" @selection-change="handleSelectionChange1">
                    <el-table-column type="selection" width="55"> </el-table-column>
                    <el-table-column prop="fileName" label="文件名称"> </el-table-column>
                </el-table>
                <div slot="footer" class="dialog-footer" style="text-align: center;">
                    <el-button @click="addSOP" type="primary">确 定</el-button>
                </div>
            </div>
            <div :style="tableDialogHeightTabPane" v-show="activeName=='fifth'">
                 <check-config :dialogForm="process.dialogForm"  @addUpdate="addUpdateHandle"></check-config>
            </div>
            <div :style="tableDialogHeightTabPane" v-show="activeName=='sixth'">
                <check-config :dialogForm="outOptConfig.dialogForm"  @addUpdate="addUpdateHandle"></check-config>
             </div>
        </el-dialog>
        <el-dialog :title="dialog4.title" width="800px" center :visible.sync="dialog4.isShow" :close-on-click-modal="false" v-dialogDrag>
        <!-- 查看文件内容 -->
        <div :style="{height:'100%',overflowY: 'auto'}">
            <div v-html="dialog4.content"></div>
        </div>
    </el-dialog>
    </div>
</template>
<script>
import api from '@/axios/api.js';
import scybHttp from '@/axios/scybHttp.js';
import cgbHttp from '@/axios/cgbHttp.js';
import checkConfig from './components/checkConfig.vue'
import checkTable from './components/checkTable.vue'
export default {
    components:{
        checkConfig,
        checkTable
    },
    data(){
        return {
             tableHeight: document.documentElement.clientHeight - 170,/**表格高度 */
             tableDialogHeightTabPane:{/**dialog style */
                height: (document.documentElement.clientHeight - 300) + 'px',
                overflowY: 'auto'
            },
            search:{
                name:'',
                code:'',
                isEnable:'',
                type:''
            },
            allMateriel:[],/**所有物料 */
            allSpareParts:[],/**所有部件 */
            allTechnicalStandard:[],/**所有技术标准 */
            allDrawing:[],/**所有图纸列表 */
            allType:[],
            allSOP:[],/**所有SOP */
            tableData:[],
            materielList:[],/**物料列表 */
            partsList:[],/**部件列表 */
            loading:false,/**加载参数 */
            dialog1:{
                title:'',
                isShow:false
            },
            dialog2:{
                title:'',
                type:'',/**机型 */
                isShow:false
            },
            dialog3:{
                title:'',
                isShow:false
            },
            dialog4:{
                title:'',
                isShow:false,
                content:''
            },
             pagination:{/**分页 */
                pageSize:10,
                currentPage:1,
                total:0
            },
             pagination1:{/**零件 */
                pageSize:10,
                currentPage:1,
                total:0
            },
            activeName:'first',
            dialogForm1:{},
            sparePartsForm:{},/** */
            materielForm:{
                cid: '',
                code:'',
                name: '',
                num: '',
                pid: '',
                type:''
            },/** 物料新增 修改表单*/
            materielRules:{
                name:[{required: true, message: '请输入物料名称', trigger: 'blur' }],
                num:[{required: true, message: '请输入物料数量', trigger: 'blur' }]
            },
            sparePartsRules:{
                name:[{required: true, message: '请输入物料名称', trigger: 'blur' }],
                num:[{required: true, message: '请输入物料数量', trigger: 'blur' }]
            },
            seclectTechnicalStandard:[],/**选中技术标准 */
            selectDrawingList:[],/** 选中图纸*/
            props1:{
                label:'drawingName',
                children:'children',
                id: 'id'
            },
            selectSOPList:[],/**选中的SOP */
            process:{/**过程配置 */
                list:[],/**过程配置列表 */
                dialogForm:{}/**新增或修改表单 */
            },
            outOptConfig:{//总装输出结果配置
                list:[],
                dialogForm:{}/**新增或修改表单 */
            },
            charger:[]/**总装工序执行人列表 */
        }
    },
    created(){
        let self = this;
        self.getTableList();


        /**获取所有技术标准 */
        api.zzAllTechnicalStandard().then(res=>{
            self.allTechnicalStandard=res.content;
        })
        /**获取所有图纸 */
        // api.zzAllDrawing().then(res=>{
        //     self.allDrawing=res.content;
        // })
        /**获取所有SOP */
        api.zzAllSOP().then(res=>{
            self.allSOP=res.content;
        })
         /**获取所有机型 */
        scybHttp.bzAllJy().then(res=>{
            res.content.forEach(el=>{
                el.value=el.type
            })
            self.allType=res.content
        })
        self.getCharger();
    },
    methods:{
        // getZzInputMaterie(){
        //     let self = this;
        //     /**获取机器总装装所有零件 */
        //     scybHttp.zzInputMaterie(self.dialog2.type).then(res=>{
        //         res.content.forEach(el=>{
        //             el.value =el.name;
        //         })
        //         self.allMateriel=res.content;
        //     })
        // },
         getCharger() {/**获取部装工序执行人列表 */
                let self = this;
                scybHttp.managersList().then(res=>{
                    self.charger = res.content;
                })
            },
        getZzAllParts(){
            let self = this;
            /** 获取机器总装所有部件*/
            scybHttp.zzAllParts(self.dialog2.type).then(res=>{
                res.content.forEach(el=>{
                    el.value =el.name;
                })
                self.allSpareParts=res.content;
            })
        },
        getTableList(){
            let self =this;
            let postData={
                currentPage:self.pagination.currentPage,
                pageSize:self.pagination.pageSize,
                name:self.search.name,
                code:self.search.code,
                isEnable:self.search.isEnable,
                type:self.search.type,
            }
            api.zzSettingList(postData).then(res=>{
               self.tableData=res.content.records;
               self.pagination.total=res.content.total;
            })
        },
        formartIsEnable(row, column, cellValue, index){
            return cellValue == 1 ? '启用' : (cellValue == 0 ? '未启用' : "");
        },
        showDialog1(type,row){
            let self = this;
            self.dialog1.title=type==='add'?'新增':'修改';
            self.dialog1.isShow=true;
            if(type==='add'){
                self.dialogForm1={
                    name:'',
                    code:'',
                    type:'',
                    typeName:'',
                    isEnable:true,
                    rank:'',
                    useTime:'',
                    nums:1,
                    performer:''
                }

            }else{
                self.allType.forEach(el=>{
                    if(el.id==row.type){
                    row.typeName=el.name;
                    }
                })
                 self.dialogForm1={
                    id:row.id,
                    name:row.name,
                    code:row.code,
                    type:row.type,
                    typeName:row.typeName,
                    isEnable:row.isEnable==1?true:false,
                    rank:row.rank,
                    useTime:row.useTime,
                    nums:row.nums,
                    performer:row.performer?Number(row.performer):'',
                    creatorName:row.creatorName,
                    createTime:row.createTime
                 };
            }

        },
        showDialog2(row){
            let self = this;
             self.dialog2.title="部件配置";
             self.dialog2.isShow =true;
             self.dialog2.type = row.type;
             self.materielForm.pid=row.id;
             self.activeName='first'
             self.getMaterielList();
             self.getPartsList();
            //  self.getZzInputMaterie();
             self.getZzAllParts();
        },
        showDialog3(type,row){
            let self = this;
             self.dialog3.isShow =true;
            switch(self.activeName){
                case 'first':
                if(type=="物料"){
                    self.dialog3.title="新增物料"
                }else{
                    self.dialog3.title="新增部件"

                }
                break;
                case 'second':
                    self.dialog3.title="技术标准配置";
                    setTimeout(function(){
                        if(self.seclectTechnicalStandard.length>0){
                        self.allTechnicalStandard.forEach((item,i)=>{
                            self.seclectTechnicalStandard.forEach(el=>{
                                if(item.fileId==el.fileId){
                                    self.$refs.multipleTable.toggleRowSelection(self.allTechnicalStandard[i],true);
                                }
                            })
                        })
                     }
                    },60)
                break;
                case 'third':
                    self.dialog3.title="图纸配置";
                     scybHttp.zzAllDrawing(self.dialog2.type,0).then(res=>{
                        self.allDrawing= res.content;
                    })
                    setTimeout(function(){
                         self.getDrawingList();
                    },60)

                break;
                case 'fourth':
                    self.dialog3.title="SOP配置";
                    setTimeout(function(){
                        if(self.selectSOPList.length>0){
                        self.allSOP.forEach((item,i)=>{
                            self.selectSOPList.forEach(el=>{
                                if(item.fileId==el.fileId){
                                    self.$refs.sop.toggleRowSelection(self.allSOP[i],true);
                                }
                            })
                        })
                        }
                    },60)
                break;
                 case 'fifth':
                    self.dialog3.title=`${type==='insert'?'新增':'修改'}装配过程检验项目配置`;
                    self.process.dialogForm = (type==='insert'?{
                        pid:self.materielForm.pid,
                        name:'',//名字
                        reference:'',//参考值
                        unit:'',//单位
                        type:'',//类型
                        isEnable:'1'//是否使用
                    }:{
                        id:row.id,
                        pid:row.pid,
                        name:row.name,//名字
                        reference:row.reference,//参考值
                        unit:row.unit,//单位
                        type:row.type,//类型
                        isEnable:String(row.isEnable)//是否使用
                    });
                break;
                 case 'sixth':
                    self.dialog3.title=`${type==='insert'?'新增':'修改'}输出结果检验项配置`;
                    self.outOptConfig.dialogForm = (type==='insert'?{
                        pid:self.materielForm.pid,
                        name:'',//名字
                        reference:'',//参考值
                        unit:'',//单位
                        rank:'',
                        type:'',//类型
                        isEnable:'1',//是否使用
                        remark:''
                    }:{
                        id:row.id,
                        pid:row.pid,
                        name:row.name,//名字
                        reference:row.reference,//参考值
                        unit:row.unit,//单位
                        rank:row.rank,
                        type:row.type,//类型
                        isEnable:String(row.isEnable),//是否使用
                        remark:row.remark
                    });
                break;
            }
        },
        showDialog4(row){
           let self = this;
            self.dialog4.isShow =true;
            self.dialog4.title=row.fileName;
            self.dialog4.content=row.initialContent;
        },
        searchData(){
            this.pagination.currentPage=1;
            this.getTableList();
        },
        handleCurrentChange(current){
            this.pagination.currentPage=current;
            this.getTableList();
        },
        handleSizeChange(size){
            this.pagination.currentPage=1;
            this.pagination.pageSize=size;
            this.getTableList();
        },
        submitClick(){
           let self = this;
           let type = self.dialog1.title.indexOf('新增')>-1?'insert':'update';
           let postdata={
                id:self.dialogForm1.id,
                name:self.dialogForm1.name,
                code:self.dialogForm1.code,
                type:self.dialogForm1.type,
                isEnable:self.dialogForm1.isEnable?1:0,
                rank:self.dialogForm1.rank,
                useTime:self.dialogForm1.useTime,
                nums:self.dialogForm1.nums,
                performer:self.dialogForm1.performer
           }
            api.addUpdateZzSetting(type,postdata).then(res=>{
                 self.$message.success(`${self.dialog1.title}成功`);
                 self.dialog1.isShow=false;
                 self.getTableList();
            },error=>{
                self.$message.error(`${self.dialog1.title}失败`)
            })
        },
        handleClick(tab, event){
            let  self= this;
           switch(self.activeName){
                case 'first':
                    self.getMaterielList();
                    self.getPartsList();
                break;
                case 'second':
                    self.getSelectTec();
                break;
                case 'third':
                   self.getDrawingList();
                break;
                 case 'fourth':
                   self.getSOPList();
                break;
                 case 'fifth':
                   self.getProcessConfigList();
                break;
                 case 'sixth':
                   self.getOutPutConfigList();
                break;
           }
        },
        querySearchAsync1(queryString, cb){
            let result=[];
            cgbHttp.searchMaterialKeyWord({name:queryString}).then(res=>{
                if(res.content&&res.content.length>0){
                    res.content.forEach(element => {
                        element.value = element.name;
                    });
                }
                result = res.content;
                cb(result);
            })
        },
        querySearchAsync2(queryString, cb){
            let self=this;
            var results = queryString ?  self.allSpareParts.filter(self.createStateFilter(queryString)) :  self.allSpareParts;
            cb(results);
        },
        createStateFilter(queryString) {
            return (state) => {
                return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) > -1);
            }
        },
        handleSelect1(item){
            let self= this;
            self.materielForm.cid=item.id;
            self.materielForm.name=item.name;
            self.materielForm.code=item.code;
            self.materielForm.type = item.type;
            self.materielForm.num=item.nums;
        },
         handleSelect2(item){
            let self= this;
            self.sparePartsForm.cid=item.id;
        },
        getMaterielList(){/**获取总装所需物料列表 */
            let self = this;
            api.zzInputMaterielList(self.materielForm.pid).then(res=>{
              self.materielList=res.content;
            })
        },
        getPartsList(){/**获取总装所需部件列表 */
            let self = this;
            api.zzInputPartsList(self.materielForm.pid).then(res=>{
              self.partsList=res.content;
            })
        },
        submitMaterielForm(){
            let self=this;
            let postData={
                pid:self.materielForm.pid,
                cid:self.materielForm.cid,
                code:self.materielForm.code,
                num:self.materielForm.num
            }
            self.$refs['materiel'].validate((valid) => {
                if (valid) {
                    api.addInputMaterie(postData).then(res=>{
                        self.$message.success(`${self.dialog3.title}成功`);
                        self.dialog3.isShow=false;
                        self.getMaterielList();
                    },error=>{
                        self.$message.error(`${self.dialog3.title}成功`);
                    })
                }
            });
        },
        submitPartsForm(){
             let self=this;
            let postData={
                pid:self.materielForm.pid,
                cid:self.sparePartsForm.cid,
                num:self.sparePartsForm.num
            }
            self.$refs['spareParts'].validate((valid) => {
                if (valid) {
                    api.addZzParts(postData).then(res=>{
                        self.$message.success(`${self.dialog3.title}成功`);
                        self.dialog3.isShow=false;
                        self.getPartsList();
                    },error=>{
                        self.$message.error(`${self.dialog3.title}成功`);
                    })
                }
            });
        },
        deleteMateriel(row){
            let self = this;
            self.$confirm('是否删除物料?', '提示', {
            confirmButtonClass: 'el-button--warning'
            }).then(() => {
                api.deleteInputMaterie(row.id).then(res=>{
                    self.$message.success(`物料删除成功`);
                    self.getMaterielList();
                },error=>{
                    self.$message.error(`物料删除成功`);
                })
            }).catch(() => {})
        },
        deleteParts(row){
            let self = this;
            self.$confirm('是否删除物料?', '提示', {
            confirmButtonClass: 'el-button--warning'
            }).then(() => {
                api.deleteParts(row.id).then(res=>{
                    self.$message.success(`部件删除成功`);
                    self.getPartsList();
                },error=>{
                    self.$message.error(`部件删除成功`);
                })
            }).catch(() => {})
        },
         deleteDrawing(row){
            let self = this;
            self.$confirm('是否移除图纸?', '提示', {
            confirmButtonClass: 'el-button--warning'
            }).then(() => {
                scybHttp.zzRemoveDrawing(row.id).then(res=>{
                    self.$message.success(`移除图纸成功`);
                    self.getDrawingList();
                },error=>{
                    self.$message.error(`移除图纸成功`);
                })
            }).catch(() => {})
        },
        handleSelectionChange(val){
            this.seclectTechnicalStandard=val;
        },
        getSelectTec(){
            let self=this;
            api.zzTechnicalStandard(self.materielForm.pid).then(res=>{
               self.seclectTechnicalStandard=res.content;
            })
        },
        addFile(){/**添加技术标准文件 */
            let self = this;
            let postData=[];
            if(self.seclectTechnicalStandard.length>0){
                self.seclectTechnicalStandard.forEach(item=>{
                    postData.push({
                        pid:self.materielForm.pid,
                        cid:item.fileId
                    })
                })
            }

            api.zzUpdataTechnicalStandard(postData).then(res=>{
                self.$message.success(`标准文件配置成功`);
                 self.dialog3.isShow=false;
                 self.getSelectTec();
            },error=>{
                self.$message.error(`标准文件配置失败`);
            })
        },
        getDrawingList(){
             let self=this;
            scybHttp.zzDrawingList(self.materielForm.pid).then(res=>{
                self.selectDrawingList=res.content;
            })
        },
        addDrawing(){
            let self = this;
            let selectArray=self.$refs.drawTress.getCheckedKeys();
            let postData=[];
            selectArray.forEach(el=>{
                postData.push({
                    pid:self.materielForm.pid,
                    cid:el
                })
            })
            scybHttp.zzUpdataDrawing(postData).then(res=>{
                 self.$message.success(`图纸配置成功`);
                 self.dialog3.isShow=false;
                 self.getDrawingList();
            },error=>{
                 self.$message.error(`图纸配置失败`);
            })
        },
        getSOPList(){
            let self=this;
            api.zzSOPList(self.materielForm.pid).then(res=>{
               self.selectSOPList=res.content;
            })
        },
         handleSelectionChange1(val){
            this.selectSOPList=val;
        },
        addSOP(){
            /**修改sop配置 */
            let self = this;
            let postData=[];
            if(self.selectSOPList.length>0){
                self.selectSOPList.forEach(item=>{
                    postData.push({
                        pid:self.materielForm.pid,
                        cid:item.fileId
                    })
                })
            }
            api.zzUpdataSOP(postData).then(res=>{
                self.$message.success(`SOP配置成功`);
                 self.dialog3.isShow=false;
                 self.getSOPList();
            },error=>{
                self.$message.error(`SOP配置失败`);
            })
        },
        getProcessConfigList(){/**获取过程信息配置列表 */
            let self=this;
            api.zzProcessList(self.materielForm.pid).then(res=>{
                self.process.list=res.content;
            })
        },
        querySearch(queryString, cb) {
            let self = this;
            var restaurants = self.allType;
            var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
        // 调用 callback 返回建议列表的数据
             cb(results);
      },
        handleSelect(item) {
           let self = this;
           self.dialogForm1.type=item.id;
        },
        getOutPutConfigList(){/**总装输出结果配置列表 */
            let self = this;
            api.finalOutPutConfigList(self.materielForm.pid).then(res=>{
                self.outOptConfig.list = res.content;
            })
        },
        addUpdateHandle(data){
            let self = this,
            type=self.dialog3.title.indexOf('新增')>-1?'insert':'update';
            switch(self.activeName){
                case 'fifth':/**新增修改过程配置 */
                    api.addUpdateProcess(type,data).then(res=>{
                        self.getProcessConfigList();
                        self.dialog3.isShow=false;
                        self.$message.success(`${self.dialog3.title}成功`)
                    },error=>{
                        self.$message.error(`${self.dialog3.title}失败`)
                    })
                    break;
                case 'sixth':
                    api.addUpdateOutPutConfig(type,data).then(res=>{
                        self.getOutPutConfigList();
                        self.dialog3.isShow=false;
                        self.$message.success(`${self.dialog3.title}成功`)
                    },error=>{
                        self.$message.error(`${self.dialog3.title}失败`)
                    })
                break;
            }
        },
        addUpdateCheck(data){
            let self = this;
            self.dialog3.isShow =true;
            let type= data.type;
            let row=data.row;
            switch(self.activeName){
                 case 'fifth':
                    self.dialog3.title=`${type==='insert'?'新增':'修改'}装配过程检验项目配置`;
                    self.process.dialogForm = (type==='insert'?{
                        pid:self.materielForm.pid,
                        name:'',//名字
                        reference:'',//参考值
                        unit:'',//单位
                        type:'',//类型
                        rank:'',
                        isEnable:'1',//是否使用
                        remark:'',
                        creatorName:'',
                        createTime:''
                    }:{
                        id:row.id,
                        pid:row.pid,
                        name:row.name,//名字
                        reference:row.reference,//参考值
                        unit:row.unit,//单位
                        type:row.type,//类型
                        rank:row.rank,
                        isEnable:String(row.isEnable),//是否使用
                        remark:row.remark,
                        creatorName:row.creatorName,
                        createTime:row.createTime
                    });
                break;
                 case 'sixth':
                    self.dialog3.title=`${type==='insert'?'新增':'修改'}输出结果检验项配置`;
                    self.outOptConfig.dialogForm = (type==='insert'?{
                        pid:self.materielForm.pid,
                        name:'',//名字
                        reference:'',//参考值
                        unit:'',//单位
                        rank:'',
                        type:'',//类型
                        isEnable:'1',//是否使用
                        remark:'',
                        creatorName:'',
                        createTime:''
                    }:{
                        id:row.id,
                        pid:row.pid,
                        name:row.name,//名字
                        reference:row.reference,//参考值
                        unit:row.unit,//单位
                        rank:row.rank,
                        type:row.type,//类型
                        isEnable:String(row.isEnable),//是否使用
                        remark:row.remark,
                        creatorName:row.creatorName,
                        createTime:row.createTime
                    });
                break;
            }
        },
        loadNode(node, resolve){
            let self = this;
            if(node.level!==0){
                scybHttp.zzAllDrawing(self.dialog2.type,node.data.id).then(res=>{
                    resolve(res.content);
                })
            }
        }
    }
}
</script>
<style scoped>
.dialog-plate-title{
    margin-bottom: 24px;
}
.dialog-plate-title .addBtn{
margin-left:24px;
}
.dec{
    color:#999;
    font-size: 12px;
    line-height: 1;
}
.width300{
    width:300px;
}
</style>
